package com.test.utils;

import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.security.PublicKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

/**
 * cer公钥解密
 *
 * @author wangjie
 * @version V1.0
 * @date 2019/12/20
 */
@Slf4j
public class Cerdemo {

    public static void main(String[] args) throws Exception{

        String strPfx = "D:\\sign.cer";
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate)cf.generateCertificate(new FileInputStream(strPfx));
        PublicKey publicKey = cert.getPublicKey();
        BASE64Encoder base64Encoder=new BASE64Encoder();
        String publicKeyString = base64Encoder.encode(publicKey.getEncoded());
        log.info("-----------------公钥--------------------");
        log.info(publicKeyString);
        log.info("-----------------公钥--------------------");
    }
}
